package com.neusoft.elm.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.neusoft.elm.po.User;
import com.neusoft.elm.service.UserService;
import com.neusoft.elm.service.impl.UserServiceImpl;
import java.io.InputStream;

public class UserController {
	public Object getUserByIdByPass(HttpServletRequest request) throws Exception {
		String userId = request.getParameter("userId");
		String password = request.getParameter("password");
		UserService service = new UserServiceImpl();
		User user = service.getUserByIdByPass(userId, password);
		return user;
	}

	public Object getUserById(HttpServletRequest request) throws Exception {
		String userId = request.getParameter("userId");
		UserService service = new UserServiceImpl();
		int result = service.getUserById(userId);
		return result;
	}

	public Object saveUser(HttpServletRequest request) throws Exception {
		User user = new User();
		user.setUserId(request.getParameter("userId"));
		user.setPassword(request.getParameter("password"));
		user.setUserName(request.getParameter("userName"));
		user.setUserSex(Integer.valueOf(request.getParameter("userSex")));
		UserService service = new UserServiceImpl();
		int result = service.saveUser(user);
		return result;
	}
	public Object updateUserPassword(HttpServletRequest request) throws Exception {
        String userId = request.getParameter("userId");
        String Oldpassword = request.getParameter("Oldpassword");
        String Newpassword = request.getParameter("Newpassword");
        UserService service = new UserServiceImpl();
        int result = service.updateUserPassword(userId, Oldpassword, Newpassword);
        return result;
    }
	public Object uploadUserAvatar(HttpServletRequest request) throws Exception {
        String userId = request.getParameter("userId");
        UserService service = new UserServiceImpl();
        InputStream inputStream = request.getInputStream();
        // 假设你有一个方法来处理输入流并保存文件
        boolean result = service.saveUserAvatarFromInputStream(userId, inputStream);
        return result ? "上传成功" : "上传失败";
    }
}
